package cn.est.controller;

import cn.est.constants.Constants;
import cn.est.dto.Result;
import cn.est.pojo.Users;
import cn.est.service.SMSService;
import cn.est.service.UsersService;
import cn.est.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class DemoController {
    @Autowired
    private UsersService usersService;

    @GetMapping("/users/{account}")
    public Users getByAccount(@PathVariable String account) {
        return usersService.getByAccount(account);
    }

    @GetMapping("/users2/{account}")
    public Result<Users> getByAccount2(@PathVariable String account) {
        Users users = usersService.getByAccount(account);
        return ResultUtil.success(users);
    }

    @Autowired
    private SMSService smsService;
    @GetMapping("/sms")
    public Result<Users> sendSms(String phone) {
        Map<String,Object> map = new HashMap<>();
        map.put("code","123456");
        smsService.sendSMS(phone, Constants.CodeType.LOGIN,map);
        return ResultUtil.success();
    }

}
